﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNADataHiding.Exceptions;

namespace DNADataHiding.Model.Shared
{
    public class BinaryCodingRule
    {
        public string ToBinary(char nucleotide)
        {
            switch (nucleotide)
            {
                case 'A':
                    {
                        return "00";
                        break;
                    }
                case 'C':
                    {
                        return "01";
                        break;
                    }
                case 'G':
                    {
                        return "10";
                        break;

                    }
                case 'T':
                    {
                        return "11";
                        break;
                    }                
            }

            throw new ModelException(string.Format("{0} is not a valid nucleotide", nucleotide));
        }

        public char FromBinary(string binaryCode)
        {
            if (binaryCode.Equals("00"))
                return 'A';
            else if (binaryCode.Equals("01"))
                return 'C';
            else if (binaryCode.Equals("10"))
                return 'G';
            else if (binaryCode.Equals("11"))
                return 'T';


            throw new ModelException(string.Format("{0} is not a valid binary code", binaryCode));
        }
    }
}
